package com.ruoyi.bizsys.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bizsys.domain.AwardRecord;
import com.ruoyi.bizsys.service.IAwardRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 奖励订单Controller
 *
 * @author african-loan
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/award/record")
public class AwardRecordController extends BaseController {
    @Autowired
    private IAwardRecordService awardRecordService;

/**
 * 查询奖励订单列表
 */
@PreAuthorize("@ss.hasPermi('bizsys:record:list')")
@GetMapping("/list")
        public TableDataInfo list(AwardRecord awardRecord) {
        startPage();
        List<AwardRecord> list = awardRecordService.selectAwardRecordList(awardRecord);
        return getDataTable(list);
    }
    
    /**
     * 导出奖励订单列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:record:export')")
    @Log(title = "奖励订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardRecord awardRecord) {
        List<AwardRecord> list = awardRecordService.selectAwardRecordList(awardRecord);
        ExcelUtil<AwardRecord> util = new ExcelUtil<AwardRecord>(AwardRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取奖励订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardRecordService.selectAwardRecordById(id));
    }

    /**
     * 新增奖励订单
     */
    @PreAuthorize("@ss.hasPermi('bizsys:record:add')")
    @Log(title = "奖励订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardRecord awardRecord) {
        return toAjax(awardRecordService.insertAwardRecord(awardRecord));
    }

    /**
     * 修改奖励订单
     */
    @PreAuthorize("@ss.hasPermi('bizsys:record:edit')")
    @Log(title = "奖励订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardRecord awardRecord) {
        return toAjax(awardRecordService.updateAwardRecord(awardRecord));
    }

    /**
     * 删除奖励订单
     */
    @PreAuthorize("@ss.hasPermi('bizsys:record:remove')")
    @Log(title = "奖励订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardRecordService.deleteAwardRecordByIds(ids));
    }
}
